$(function() {

    const pros1 = new Promise((resolve, reject) => {

        $.ajax(`${baseUrl}/categories/count`, {
            success: function(res) {
                // console.log('分类数量1', res);
                resolve(res)
            },
            error: function(err) {
                console.log('err', err);
                reject(err)
            }
        })

    })
    const pros2 = new Promise((resolve, reject) => {
        $.ajax(`${baseUrl}/posts/count`, {
            success: function(res) {
                // console.log('文章数量2', res);
                resolve(res)
            },
            error: function(err) {
                console.log('err', err);
                reject(err)
            }
        })
    })
    const pros3 = new Promise((resolve, reject) => {

        $.ajax(`${baseUrl}/comments/count`, {
            success: function(res) {
                // console.log('评论数量3', res);
                resolve(res)
            },
            error: function(err) {
                console.log('err', err);
                reject(err)
            }
        })
    })

    Promise.all([pros1, pros2, pros3]).then(res => {
        // console.log('promise all:', res);
        // console.log('...res', ...res);
        let tempObj = {}
        res.forEach(item => {
            for (let key in item) {
                tempObj[key] = item[key];
            }
        })
        console.log(tempObj);
        const newHtml = template('list-group-id', tempObj)
        console.log('newHTml', newHtml);
        $('.list-group').html(newHtml);
    }).catch(err => {
        console.log(err);
    });


    // pros1.then(res => {
    //     console.log('===========1============');
    //     return pros2;
    // }).then(res => {
    //     console.log('---------------2---------------');
    //     return pros3
    // }).then(res => {
    //     console.log('---------------3---------------');

    // })

})